package com.hupu.jrs.ui

import android.os.Bundle
import android.view.View

/**
 * Created by sll on 2016/1/14.
 */
abstract class BaseLazyLoadFragment : BaseFragment() {

    private var isFirstLoad = true

    override fun onViewCreated(view: View, savedInstanceState: Bundle) {
        initInjector()
        getBundle(getArguments())
        initUI(view)
    }

    override fun onResume() {
        super.onResume()
        if (getUserVisibleHint()) {
            onVisible()
        }
    }

    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
        if (isVisibleToUser) {
            onVisible()
        }
    }

    private fun onVisible() {
        if (isFirstLoad && isPrepare) {
            initData()
            isFirstLoad = false
        }
    }
}
